<%--
  User: ganesh
  Date: May 30, 2007
  Time: 2:52:55 PM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/costCodeSetupAction.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
    window.onload = init;
    var listSize=0;

    function init()
    {
        qs_1 = new QuickSearch( document.productCostCodeSetupForm.processStepId, document.productCostCodeSetupForm.qs1, false );
    }
    function reset()
    {

        document.productCostCodeSetupForm.reset();
        qs_1.resetQuickSearchCntrl();
        var form = document.productCostCodeSetupForm;
        for ( var i=0; i< listSize; i++)
        {
            enableDisableCostCodes(i);
        }
    }
    function packagePinDetails()
    {
        var form = document.productCostCodeSetupForm;
        if (form.processStepId.value > 0)
        {
            form.packageType.value = 0;
            form.pinType.value = 0;
        }
    }
    function partNumberDetails()
    {
        var form = document.productCostCodeSetupForm;
        if ( form.packageType.value > 0 )
        {
            form.processStepId.value = 0;
        }
        if ( form.pinType.value > 0 )
        {
            form.processStepId.value = 0;
        }
    }
    function submitPage()
    {
        var form    = document.productCostCodeSetupForm;
        form.action = "<%=chipTracContext%>/productCostCodeSetupAction.do?action=loadCostCodes"
        form.submit();
    }
    function savePage()
    {
        var form    = document.productCostCodeSetupForm;
        form.action = "<%=chipTracContext%>/productCostCodeSetupAction.do?action=saveCostCodes"
        form.submit();
    }
    function costChecked(idx)
    {
        var form = document.productCostCodeSetupForm;
        var chkbox = form['costCodePartNumbersList['+idx+'].checked'];
        chkbox.checked = true;        
    }
    function enableDisableCostCodes(idx)
    {
        var form = document.productCostCodeSetupForm;
        var chkbox = form['costCodePartNumbersList['+ idx +'].checked'];
        if( chkbox.checked  )
        {
            document.productCostCodeSetupForm['costCodePartNumbersList['+ idx +'].costCode'].disabled = false;
        }
        else
        {
          document.productCostCodeSetupForm['costCodePartNumbersList['+ idx +'].costCode'].disabled = true;
        }
    }
    function save()
    {
        var form = document.productCostCodeSetupForm;
        var count=0;
        var pa=document.getElementById("errors");
        pa.innerHTML ='';
        for( var i = 0; i < listSize; i++ )
        {
            if( document.productCostCodeSetupForm[ 'costCodePartNumbersList[' + i + '].checked' ].checked )
            {
                count++;
                break;
            }
        }
        if( count == 0 )
        {
            var pa = document.getElementById("errors");
            pa.innerHTML = "<li> Check one or more Checkboxes to Set up the Cost Code ";
            return;
        }
        else
        {
            form.action = "<%=chipTracContext%>/productCostCodeSetupAction.do?action=saveCostCodes"
            form.submit();
        }
    }
</SCRIPT>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
	    <!-- Side Navigation start -->
	    <%@include file="/jsp/finance/finance_menu.jsp" %>
	    <!-- end of the side navigations -->
        </TD>
	    <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	    <TD valign="top" width="100%"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	    <BR>
        <html:form action="/productCostCodeSetupAction.do" name="productCostCodeSetupForm" type="com.scalar.chiptrack.finance.creditNote.forms.productCostCodeSetupForm">
            <input type="hidden" name="isSearchSubmit" value="true">
            <TABLE width="80%" align="center" cellpadding="2" cellspacing="2" border="0">
			    <TR><TD colspan="5" class="NArialW" align="center">Product Cost Code Setup </TD></TR>
			    <TR><TD colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"/><chiptrack:info styleClass="NArialL"/></TD></TR>
			    <TR><TD colspan='5' class="NArialL"><FONT id="errors" color='FF0000'></font></TD></TR>
                <tr>
                    <td class="NArialL" nowrap>
                        Quick Search Part Number:
                    </td>
                    <td class="NArialL">
                        <input type="text" name="qs1" class="txfield" size='12' onkeyup='quickSearch(qs_1)'/>
                    </td>
                    <td width="5%">&nbsp;</td>
                    <td class="NArialL" width='20%'>
                        &nbsp;
                    </td>
                    <td class="NArialL" width='20%'>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        Marketing Part Number:
                    </td>
                    <td class="NArialL">
                        <nested:select name="productCostCodeSetupForm" property="processStepId"  styleClass="txfield" onchange="packagePinDetails()" >
                            <html:option value="0">All Part Number</html:option>
                            <logic:present name="partNumberList">
                                <html:options collection="partNumberList" property="value" labelProperty="label"/>
                            </logic:present>
                        </nested:select>
                    </td>
                    <td width="5%">&nbsp;</td>
                    <td class="NArialL" width="10%">
                        Package:
                    </td>
                    <td class="NArialL" align="left">
                        <nested:select name="productCostCodeSetupForm" property="packageType"  styleClass="txfield" onchange="partNumberDetails()">
                            <html:option value="0">All Packages</html:option>
                            <logic:present name="packagesList">
                                <html:options collection="packagesList" property="value" labelProperty="label"/>
                            </logic:present>
                        </nested:select>
                    </td>
            </tr>
            <tr>
			    <td class="NArialL" nowrap>
			         Pin Count:
			    </td>
			    <td class="NArialL">
                    <nested:select name="productCostCodeSetupForm" property="pinType"  styleClass="txfield" onchange="partNumberDetails()">
                        <html:option value="0">All Pins</html:option>
                        <logic:present name="pinsList">
                            <html:options collection="pinsList" property="value" labelProperty="label"/>
                        </logic:present>
                    </nested:select>
			    </td>
                <td class="NArialL" width="5%">&nbsp;</td>
                <td class="NArialL" colspan="2"> <nested:checkbox property="withoutCostCode" styleClass="txfield">&nbsp; Part Numbers With Out Cost Codes </nested:checkbox> </td>
                <%--<td class="NArialL">&nbsp; </td>--%>
            </tr>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
			<tr>
				<td colspan="5" align="center">
                    <a href="javascript:submitPage()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search Product Cost Code ';return true" onmouseout="window.status='';return true" title="Click here to Search Product Cost Code" alt=""></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				    <a href="javascript:reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
				</td>
			</tr>

            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <nested:present property="costCodePartNumbersList">
            <nested:size id="listSize" property="costCodePartNumbersList"/>
                <script type="text/javascript">
                    listSize=<%=listSize.intValue() %>;
                </script>
            <logic:greaterThan value="0" name="listSize" >
            <tr>
                <td colspan="5"  >
                    <table width="100%">
                        <tr bgcolor="#993333">
                            <td align="center" class="NArialL"><font color="#FFFFFF">Select </font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Mkt Part Number </font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Base Product</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Package </font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Pin </font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Cost Code</font></td>
                        </tr>
                    <nested:iterate id="costCodePartNumbersId" property="costCodePartNumbersList" indexId="iterateIdx" >
		            <tr bgcolor=<%=iterateIdx.intValue() % 2 == 0 ? "'#FFFFEE'" : "'#DEE1E2'"%> >
                       <nested:hidden property="processStepId"/>
                        <%
                                String onchange = "enableDisableCostCodes(" + iterateIdx.toString() + ")";
                        %>
                        <td align="center" class="NArialL" ><nested:checkbox property="checked" styleClass="txfield" onclick="<%=onchange%>"/></td>
                        <td align="center" class="NArialL" ><nested:write property="marketingPartNumber"/></td>
                        <td align="center" class="NArialL" ><nested:write  property="baseProduct"/></td>
                        <td align="center" class="NArialL" ><nested:write  property="packageType"/></td>
                        <td align="center" class="NArialL" ><nested:write  property="pinType"/></td>
                        <nested:hidden property="costCodeListSize" value="listSize"/>
                        <td align="center" class="NArialL">

                            <%--onchange="<%=onchange%>"--%>
                           <nested:select property="costCode"  styleClass="txfield" disabled="true" >
                               <html:option value="0">Select Cost Code</html:option>
                                <logic:present name="costCodeList" >
                                    <html:options collection="costCodeList" property="value" labelProperty="label"/>
                                </logic:present>
                            </nested:select>
                        </td>
                    </tr>
                    </nested:iterate>
                    </table>
                </td>
            </tr>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <tr>
                <td colspan="5" align="center">
                    <a href="javascript:save()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17" onmouseover="window.status='Click to Search Product Cost Code';return true" onmouseout="window.status='';return true" title="Click here to save Cost code Setup " alt=""></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
                </td>
            </tr>
            </logic:greaterThan>
        </nested:present>
        </TABLE>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>
